import request from '@/utils/request'

/**
 *  分页查询
 * @param pageNum
 * @param pageSize
 * @param queryRequest
 * @returns {*}
 */
export const getRoleList = (pageNum, pageSize, queryRequest) => {
  return request({
    url: `/user/system/sysRole/findRoleByPage/${pageNum}/${pageSize}`,
    params: queryRequest,
    method: 'get',
  })
}
/**
 * 添加用户
 * @param sysRole
 * @returns {*}
 */
export const doAddRole = sysRole => {
  return request({
    url: `/user/system/sysRole/addRole`,
    data: sysRole,
    method: 'post',
  })
}
/**
 *  获取角色信息
 * @param id
 * @returns {*}
 */
export const doFindRoleById = id => {
  return request({
    url: `/user/system/sysRole/findById/${id}`,
    method: 'GET',
  })
}

/**
 *  修改角色
 * @param id
 * @returns {*}
 */
export const doChangeRole = sysRole => {
  return request({
    url: `/user/system/sysRole/updateById`,
    method: 'PUT',
    data: sysRole,
  })
}

/**
 *  根据id删除角色
 * @param id
 * @returns {AxiosPromise}
 * @constructor
 */
export const deleteSysRoleById = id => {
  return request({
    url: `/user/system/sysRole/deleteById/${id}`,
    method: 'delete',
  })
}

/**
 *  批量删除
 * @param id
 * @returns {AxiosPromise}
 * @constructor
 */
export const doBatchDelete = idList => {
  return request({
    url: `/user/system/sysRole/batchDelete`,
    method: 'delete',
    data: idList,
  })
}

/**
 *  查询菜单树
 * @returns {*}
 */
export const findMenuTree = () => {
  return request({
    url: `/user/system/sysMenu/findMenuTree`,
    method: 'GET',
  })
}

/**
 *  根据角色id查询菜单
 * @returns {*}
 */
export const findMenuByRoleId = id => {
  return request({
    url: `/user/system/sysRoleMenu/findMenuByRoleId/${id}`,
    method: 'GET',
  })
}

/**
 *  分配菜单
 * @returns {*}
 */
export const doUpdateRoleMenu = (id, menuIds) => {
  return request({
    url: `/user/system/sysRoleMenu/updateRoleMenu/${id}`,
    method: 'POST',
    data: menuIds,
  })
}
